<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="cleartype" content="on">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>签到中心</title>
	<link rel="stylesheet" href="<%=basePath%>static/css/public.css" />
	<link rel="stylesheet" href="<%=basePath%>static/css/signin.css" />
	<link rel="stylesheet" href="<%=basePath%>static/css/alert.css" />
	<link rel="stylesheet" href="<%=basePath%>static/css/style4.css" />
	<link href="<%=basePath%>static/css/bootstrap-popover-x.css" media="all"
		  rel="stylesheet" type="text/css" />
	<!-- <script src="js/bootstrap.min.js"></script> -->
	<style>
		#mb_btn_ok, #mb_btn_no{
			-webkit-appearance:none;
		}
	</style>
</head>
<body>
<div
		class="top flex flex-align-end flex-pack-center flex-warp container ">
	<div class="balance">
		<div class="position_center">
			<c:if test="${isShunTong == true }">
				<div>
					已获得的积分金额：<span style="color: #f38d43;">${callbalance }</span> <br>
					已获得的购物金额：<span style="color: #f38d43;">${shopbalance }</span>
				</div>
			</c:if>
			<c:if test="${isShunTong != true }">
			<div>
				已获得的通话金额：<span style="color: #f38d43;">${callbalance }</span> <br>
				已获得的购物金额：<span style="color: #f38d43;">${shopbalance }</span>
			</div>
			</c:if>
		</div>
		<div class="well text-center" style="text-align: right; color: #bbb;">
			<button class="btn btn-primary btn-lg"
					style="text-align: right; color: #334982; background-color: transparent; font-size: 13px;"
					data-toggle="popover-x" data-target="#myPopover20a"
					data-placement="left left-top" id='btn_rule'>规则说明</button>
		</div>
	</div>

	<div class="out-2 flex flex-align-center flex-pack-center"
		 style="text-align: center;">
		<div class="signBtn img-responsive">
			<strong id="sign-txt"><c:if test="${dayWeek == true }">已</c:if>签到</strong>
		</div>
	</div>

	<div class="tips">
			<span>已连续签到<em id="sign-count">${continuity }</em>天
			</span>
	</div>
</div>

<!-- 签到系统 -->
<div class="Calendar">
	<div class="calendar">
		<c:forEach items="${signList}" var="s" varStatus="z">
			<div>
					<span <c:if test="${s.sign == true }">id="day-active"</c:if>>${s.week }
						<p class="dingwei" style="width: 35px">${s.day }</p>
					</span>
			</div>
		</c:forEach>
	</div>
	<p class="line"></p>
</div>
<br />

<!-- 任务start -->
<div class="task">
	<div class="row" style="padding-left: 0.6rem;">
		<c:if test="${trsize == 0}">
			<span>今日无签到任务</span>
		</c:if>
		<c:if test="${trsize != 0}">
			<span class="box"></span>&nbsp;<span>今日签到任务</span>
		</c:if>
	</div>
	<div style="margin-top: 0.8rem;">
		<c:forEach items="${trList}" var="s" varStatus="z">
			<div class="news">
				<div class="news1 row">
					<div class="row">
						<div style="margin-top: 0.2rem; text-align: left;">
							<p>
								<c:if test="${s.taskList.type==1}">登录${s.taskList.target }次软件</c:if>
								<c:if test="${s.taskList.type==2}">分享${s.taskList.target }次软件</c:if>
								<c:if test="${s.taskList.type==3}">购买${s.taskList.target }次商品</c:if>
								<c:if test="${s.taskList.type==4}">浏览${s.taskList.target }次广告</c:if>
								<c:if test="${s.taskList.type==5}">浏览${s.taskList.target }次新闻</c:if>
								<c:if test="${s.taskList.type==6}">完善${s.taskList.target }次个人信息</c:if>
							</p>
							<div class="row small_text">
								<p>
									领
									<c:if test="${s.taskList.presenttf !='0.00'}">话费<span
										style="color: #F1B844">${s.taskList.presenttf }</span>元
									</c:if>
									<c:if test="${s.taskList.presentsg !='0.00'}">
										购物金<span style="color: #F1B844">${s.taskList.presentsg }</span>元
									</c:if>
								</p>
							</div>
						</div>
					</div>
					<button id="btn-text" class="Btn"
							onclick="upStatus('${s.id}','${s.receivestatus}','${s.completestatus}','${s.taskList.type}')">
						<c:if test="${s.receivestatus == 0 }">领取任务</c:if>
						<c:if test="${s.receivestatus == 1 }">
							<c:if test="${s.completestatus == 0 }">
								完成中
							</c:if>
							<c:if test="${s.completestatus == 1 }">
								领取奖励
							</c:if>
							<c:if test="${s.completestatus == 2 }">
								已领取
							</c:if>
						</c:if>
					</button>
				</div>
			</div>
		</c:forEach>
	</div>
</div>
<div style="height:1rem;"></div>
<script src="<%=basePath%>static/js/jquery-1.11.0.min.js"
		type="text/javascript"></script>
<script
		src="http://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="<%=basePath%>static/js/bootstrap-popover-x.js"
		type="text/javascript"></script>
<script type="text/javascript" src="<%=basePath%>static/js/rili.js"></script>
<script type="text/javascript" src="<%=basePath%>static/js/ui.js"></script>
<script type="text/javascript" src="<%=basePath%>static/js/alert_tip.js"></script>
<script language="JavaScript">
	//判断是否是安卓还是ios
	function isAndroid_ios() {
		var u = navigator.userAgent,
				app = navigator.appVersion;
		var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //android终端或者uc浏览器
		var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
		return isAndroid == true ? true : false;
	}
	//任务跳转
	function TaskTip(words) {
		console.log(words);
		if (isAndroid_ios()) {
			Contents.TaskTip(words);
		} else {
			console.log("ios");
			window.webkit.messageHandlers.TaskTip.postMessage(words);
		}
	}
	function TaskClick(type){
		var words = '';
		if(type==1){
			words = '登录软件'
		}else if(type==2){
			words = '分享软件'
		}else if(type==3){
			words = '购买商品'
		}else if(type==4){
			words = '浏览广告'
		}else if(type==5){
			words = '浏览新闻'
		}else if(type==6){
			words = '完善个人信息'
		}

		TaskTip(words);
	}
	// 签到
	$('#sign-txt').click(function() {
		if ('${dayWeek}' == 'true') {
			zdalert("","今日已签到");
			return;
		}
		$.ajax({
			type : 'POST',
			url : 'addWeeks',
			data : {
				subid : '${subid}',
				continuity : '${continuity}'
			},
			dataType : 'json',
			success : function(date) {
				switch (date.flag) {
					case -1:
						zdalert("","非法操作");
						break;
					case -2:
						zdalert("","今日已签到");
						location.href = "weeksApp?subid=${subid}";
						break;
					case -3:
						zdalert("","签到失败，请重试");
						location.href = "weeksApp?subid=${subid}";
						break;
					case -100:
						zdalert("","过期账户无法签到");
						break;
					default:
						zdalert("","签到成功，请查收自己的余额");
						TaskClick();
						location.href = date.adv;
						break;
				}
			}
		});
	});
	// 任务
	function upStatus(id, receivestatus, completestatus, type) {
		console.log(type);
		if (receivestatus == '1' && completestatus == '0') {
			zdalert("","当前任务正在完成中");
			return;
		}
		if (completestatus == '2') {
			zdalert("","当前任务已领取奖励，快去看看其他任务吧");
			return;
		}
		$.ajax({
			type : 'POST',
			url : 'updateTasks',
			data : {
				subid : '${subid}',
				id : id
			},
			success : function(date) {
				switch (date) {
					case -1:
						zdalert("","非法操作");
						break;
					case -2:
						zdalert("","任务奖励领取失败，请重试");
						location.href = "weeksApp?subid=${subid}";
						break;
					case 0:
						zdalert("","任务奖励领取成功，请查收自己的余额");
						TaskClick(type);
						location.href = "weeksApp?subid=${subid}";
						break;
					case 1:
						zdalert("","任务领取成功，快去完成吧");
						TaskClick(type);
						location.href = "weeksApp?subid=${subid}";
						break;
					case 2:
						zdalert("","当前任务正在完成中");
						location.href = "weeksApp?subid=${subid}";
						break;
					case 3:
						zdalert("","当前任务已领取奖励");
						location.href = "weeksApp?subid=${subid}";
						break;
					case -100:
						zdalert("","过期账户无法领取奖励");
						break;
				}
			}
		});
	}
	// 规则
	$('#btn_rule').click(function() {
		var rule = "${rule}";
		if (rule.length == 0) {
			rule = "<p>暂未设置规则说明</p>";
		}
		mizhu.alert("规则说明", rule);
	});
</script>
</body>
</html>